# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Michał Polański <michal@polanski.me>
pkgname=hcloud
pkgver=1.30.0
pkgrel=1
pkgdesc="Command-line interface for Hetzner Cloud"
url="https://github.com/hetznercloud/cli"
license="MIT"
arch="all"
makedepends="go"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/hetznercloud/cli/archive/v$pkgver/hcloud-$pkgver.tar.gz"
builddir="$srcdir/cli-$pkgver"

export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw"
export GOPATH="$srcdir"
export CGO_ENABLED=0

build() {
	go build \
		-ldflags "-X github.com/hetznercloud/cli/internal/version.Version=$pkgver" \
		-v \
		./cmd/hcloud

	./hcloud completion bash > $pkgname.bash
	./hcloud completion fish > $pkgname.fish
	./hcloud completion zsh > $pkgname.zsh
}

check() {
	go test ./...
}

package() {
	install -Dm755 hcloud "$pkgdir"/usr/bin/hcloud

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/completions/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
97a5a560c15cbb5f7db50f87fc387d2c35912909f6fcdf8004a3826b418c37d255b1ddcdc4d1829f2e00166e4f22a525915d70f8d927cd7d35386d8303fff4e2  hcloud-1.30.0.tar.gz
"
